feat(mac): add BACKEND={llamacpp|mlx} knob for native MLX inference - #4
Open
soobrosa wants to merge 2 commits into
Open
feat(mac): add BACKEND={llamacpp|mlx} knob for native MLX inference#4soobrosa wants to merge 2 commits into
soobrosa wants to merge 2 commits into
Conversation
Opt-in MLX inference backend alongside the default llama.cpp path. BACKEND=mlx serves Qwen3.6-35B-A3B via mlx_lm.server for ~6x faster prefill on Apple Silicon, with context auto-capped to MLX_CTX_CAP (75K) under the fp16-KV OOM ceiling and MODEL_ID pinned so the agent's requests match the loaded model. Default behavior is unchanged. docs/MAC.md gains an MLX backend section. Quantized KV (kv4, ~92-113K ceiling) is pending upstream ml-explore/mlx-lm#1043 (server lacks --kv-bits); once merged, enable it and raise the cap. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
soobrosa
force-pushed
the
feat/mlx-backend-knob
branch
from
June 5, 2026 16:07
de47d77 to
c22fcd4
Compare
Detects --kv-bits in mlx_lm.server (ml-explore/mlx-lm#1353); when present, serves with --kv-bits 4 --kv-group-size 64 and raises MLX_CTX_CAP 75K->85K (verified greedy-lossless + long-ctx recall). Falls back to fp16 KV + 75K cap on stock mlx-lm, so the change is safe before #1353 ships. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
BACKEND={llamacpp|mlx}knob toscripts/mac-run.shso Apple Silicon users can serve Qwen3.6-35B-A3B via mlx-lm for much faster prefill, while keeping llama.cpp as the stable default. Newdocs/MAC.mddocuments the tradeoffs and setup.BACKEND=llamacppreproduces today's llama.cpp (Metal, GGUF, MTP) path exactly.BACKEND=mlxrunsmlx_lm.serverfrom an isolated.venv-mlxon:8080(sameLLAMA_URL), servingmodels/mlx/Qwen3.6-35B-A3B-UD-MLX-4bit.Why
Measured on M3 Pro / 36 GB (vs the committed llama.cpp baseline):
Prefill dominates the compaction-heavy agent loop, so this is the win that matters for long autonomous jobs.
Notable behaviors (documented in
docs/MAC.md)mlx_lm.serverruns an fp16 KV cache (no--kv-bitsflag — upstream ml-explore/mlx-lm#1043). fp16 KV OOMs at ~78–92K actual tokens on 36 GB, so context is auto-capped toMLX_CTX_CAP(75K), comfortably above the defaultCTX_SIZEof 65536.MODEL_IDpinned.mlx_lm.serverresolves the request'smodelagainst the loaded model (and otherwise tries HuggingFace), so the script pinsMODEL_IDto the model path for this backend. llama.cpp keeps the friendlyqwen3.6label./metrics,/slots), so those live widgets stay blank undermlx; jobs run and package normally.Correctness
Tool-calling (structured
tool_calls), streaming, and the agent loop work via the model's bundled chat template.--kv-bits 4(validated on the non-server path) is greedy-lossless with 15/15 long-context fact recall at 83.5K — it'll come to the server once mlx-lm#1043 lands, after which we flip on quantized KV and raise the cap to ~85K (kv4 ceiling ~92–113K).Test plan
Verified locally:
/healthready, tool-calling returns structuredtool_calls, SSE streaming works, context auto-cap applied.